import React from 'react'
import { NavBar} from "antd-mobile";
import { useNavigate } from 'react-router-dom';
import { List, Switch } from 'antd-mobile';
import { useEffect } from 'react';
import { getLogin,getEdit } from '../../api/index';
import { useState } from 'react';
export default function MessageSetting() {
    const navigate = useNavigate()
    const [user,setUser] = useState({})
    const [flag,setFlag] = useState({})
    const back = () => {
        navigate(-1);
      };
      useEffect(()=>{
        let userid = JSON.parse(localStorage.getItem('user')).id
        getLogin().then(res=>{
          let obj = res.data.find(item => item.id == userid)
          setUser(obj)
        })
      },[flag])
  return (
    <>
        <NavBar onBack={back}>消息设置</NavBar>
        <List>
            <List.Item extra={<Switch onChange={(e)=>{
              if (e) {
                getEdit({id:user.id,infor:1}).then(res=>{
                  if (res.code == 200) {
                    setFlag({})
                  }
                })
              }else{
                getEdit({id:user.id,infor:0}).then(res=>{
                  if (res.code == 200) {
                    setFlag({})
                  }
                })
              }
            }} checked={user.infor} defaultChecked />}>不接受任何消息</List.Item>
        </List>
    </>
  )
}
